package org.example.admin.controller;

import org.example.admin.exception.ControllerException;
import org.example.admin.exception.ServiceException;
import org.example.admin.service.ReportService;
import org.example.entity.Cart;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@CrossOrigin("*")
@RestController
@RequestMapping("/admin")
public class ReportController {

    @Resource
    ReportService reportService;

    @GetMapping("/getCartInfo")
    public Object getCartInfo(){
        List<Cart> list = null;
        try{
            list = reportService.getCartInfo();
        }catch (ServiceException e){
            throw e;
        }catch (Exception e){
            throw new ControllerException("控制层异常"+e.getMessage());
        }
        return list;
    }

    @RequestMapping("/num")
    public Object getNums(){
        int nums = 0 ;
        try{
            nums = reportService.getNums();
        }catch (ServiceException e){
            throw e;
        }catch (Exception e){
            throw new ControllerException("控制层异常"+e.getMessage());
        }

        return nums;
    }

    @RequestMapping("/nearly7Days")
//    @GetMapping("/nearly7Days")
    public Object getNearly7Days(){
        List<Map<String,String>> list = null;
        try{
            list = reportService.getNearly7Days();
        }catch (ServiceException e){
            throw e;
        }catch (Exception e){
            throw new ControllerException("控制层异常"+e.getMessage());
        }
        return list;
    }

    @RequestMapping("/nearly30Days")
    public Object getNearly30Days(){
        List<Map<String,String>> list = null;
        try{
            list = reportService.getNearly30Days();
        }catch (ServiceException e){
            throw e;
        }catch (Exception e){
            throw new ControllerException("控制层异常"+e.getMessage());
        }
        return list;
    }

    @RequestMapping("/sale")
    public Object sales(){
        Map<String, List> data = null;
        try{
            reportService.getSales();
        }catch (ServiceException e){
            throw e;
        }catch (Exception e){
            throw new ControllerException("控制层异常"+e.getMessage());
        }

        return data;
    }
    @RequestMapping("/totalSales")
    public Object totalSales(){
        long totalSales = 0L;
        try{
            totalSales = reportService.getTotalSales();
        }catch (ServiceException e){
            throw e;
        }catch (Exception e){
            throw new ControllerException("控制层异常"+e.getMessage());
        }
        return totalSales;
    }

    @RequestMapping("/salesShare")
    public Object salesShare(){
        List<Map<String, String>> list = null;
        try{
            list = reportService.getSalesShare();
        }catch (ServiceException e){
            throw e;
        }catch (Exception e){
            throw new ControllerException("控制层异常"+e.getMessage());
        }
        return list;
    }
}
